package freaks.terah.model;

import java.awt.Color;
import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;

public class APListRenderer extends DefaultListCellRenderer {
    
  /**
	 * 
	 */
  private static final long serialVersionUID = 1L;
  PlayerModel theModel;

  /** Creates a new instance of ColorRenderer */
  public APListRenderer(PlayerModel aModel) {
	  theModel = aModel;
  }
    
  public Component getListCellRendererComponent(JList list, 
                                                Object value,
                                                int index, 
                                                boolean isSelected,
                                                boolean cellHasFocus) {

    super.getListCellRendererComponent(list, 
                                       value, 
                                       index, 
                                       isSelected, 
                                       cellHasFocus);
    if (value instanceof Ressource) {
      Ressource res = (Ressource) value;
      setText(res.getName());
      
      if (!theModel.canBuy(res))
          setForeground(Color.LIGHT_GRAY);
      else
    	  setForeground(Color.BLACK);
    }
    return this;
  }
}